package cn.design;

import cn.design.realize.Aggregate;
import cn.design.realize.ConcreteAggregate;
import cn.design.realize.Iterator;

/**
 * @author dlq
 * @description 迭代模式的客户端类： IteratorClientDemo
 * @date 2020/10/9 13:42
 * @since 1.0
 */
public class  IteratorClientDemo{

    public static  void main(String[] args) {
        //1. 定义一个数组
        String[] s = {"a","b","c","d"};
        //2. 聚合
        Aggregate<String> aggregate =  new ConcreteAggregate<>(s);

        //3.获取迭代器
        Iterator<String> iterable = aggregate.iterator();
        System.out.println("第一个元素： "+iterable.first());

        //4.遍历元素
        while (iterable.hasNext()){
            String temp = iterable.next();
            System.out.println("元素遍历： " + temp);
        }


    }
}
